#include "../stdafx.h"
#include "Light.h"

CLight::CLight()
{
	m_lightIndex = 0;
	GLfloat diffuseLights[] = {0.0, 0.0, 1.0, 1.0};
	GLfloat specularLights[] = {0.0, 0.0, 1.0, 1.0};
	GLfloat position[] = {40.0, 50.0, 30.0, 1.0};
	for (int i = 0; i < 4; i++)
	{
		m_relPosition[i] = position[i];
		m_diffLight[i] = diffuseLights[i];
		m_specularLight[i] = specularLights[i];
	}
}

void CLight::SetLightIndex(int index)
{
	m_lightIndex = index;
	m_lightIndex = (m_lightIndex < 0) ? 0 : m_lightIndex;
}

void CLight::SetLightParas(float position[], float diffusion[], float specular[])
{
	if (position)
	{
		for (int i = 0; i < 4; i++)
			m_relPosition[i] = position[i];
	}
//	glLightfv(GL_LIGHT0 + m_lightIndex, GL_POSITION, m_relPosition);
	if (diffusion)
	{
		for (int i = 0; i < 4; i++)
			m_diffLight[i] = diffusion[i];
	}
	glLightfv(GL_LIGHT0 + m_lightIndex, GL_DIFFUSE, m_diffLight);
	if (specular)
	{
		for (int i = 0; i < 4; i++)
			m_specularLight[i] = specular[i];
	}
	glLightfv(GL_LIGHT0 + m_lightIndex, GL_SPECULAR, m_specularLight);
}

void CLight::GetLightRelPosition(float position[])
{
	for (int i = 0; i < 4; i++)
		position[i] = m_relPosition[i];
}

void CLight::SetLightGlobalPosition(float position[])
{
	glLightfv(GL_LIGHT0 + m_lightIndex, GL_POSITION, position);
}

void CLight::EnableLight()
{
	glEnable(GL_LIGHT0 + m_lightIndex);
}

void CLight::DisableLight()
{
	glDisable(GL_LIGHT0 + m_lightIndex);
}
